package com.dragon.common.core.util;

import com.dragon.common.core.constant.CommonConstants;
import lombok.Data;

import java.io.Serializable;

/**
 * @date: 2024/8/5 22:30
 * @author: ybl
 */
@Data
public class R<T> implements Serializable {

    private int code;

    private String msg;

    private T data;

    public static <T> R<T> success() {
        return result(null, CommonConstants.SUCCESS, null);
    }

    public static <T> R<T> success(T data) {
        return result(data, CommonConstants.SUCCESS, null);
    }

    public static <T> R<T> fail(String msg) {
        return result(null, CommonConstants.FAIL, msg);
    }


    public static <T> R<T> result(T data, int code, String msg) {
        R<T> result = new R<>();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }
}
